/*
 * $Id: Permission.java 15 2014-08-17 14:20:24Z ratking $
 *
 * Copyleft (C) 2014 RatKing. All wrongs reserved.
 */
package cn.ratking.demo.jaws6.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * 权限
 */
@Entity
@Table(name = "T_Permission",
        uniqueConstraints = {
            @UniqueConstraint(columnNames = "permissionCode")
        })
public class Permission implements Serializable {

    /** 权限ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long permissionId;
    /** 权限代码(不得重名) */
    @NotNull
    @Size(min = 1, max = 20)
    @Column(unique = true)
    private String permissionCode;
    /** 上级代码 */
    @Size(max = 20)
    private String pcode;
    /** 权限名称 */
    @NotNull
    @Size(min = 1, max = 20)
    private String permissionName;
    /** 权限类型(菜单、功能) */
    @NotNull
    @Size(min = 1, max = 20)
    private String type;
    /** 级别 */
    private int permissionLevel;
    /** URL地址 */
    @Size(max = 200)
    private String url;
    /** 排序序号 */
    private int orderNo;
    /** 是否启用(false/0-禁用 true/1-启用) */
    private boolean enabled;
    /** 备注 */
    @Size(max = 1000)
    private String remark;
    /** 创建时间 */
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;
    /** 更新时间 */
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    /** 版本(用于JPA乐观锁) */
    @Version
    private int version;

    /** 无参构造方法 */
    public Permission() {
    }

    public Long getPermissionId() {
        return permissionId;
    }

    public void setPermissionId(Long permissionId) {
        this.permissionId = permissionId;
    }

    public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }

    public String getPcode() {
        return pcode;
    }

    public void setPcode(String pcode) {
        this.pcode = pcode;
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPermissionLevel() {
        return permissionLevel;
    }

    public void setPermissionLevel(int permissionLevel) {
        this.permissionLevel = permissionLevel;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(int orderNo) {
        this.orderNo = orderNo;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(permissionId);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof Permission)) {
            return false;
        }
        final Permission other = (Permission) obj;
        return Objects.equals(this.permissionId, other.permissionId);
    }

    /**
     * 返回测试字符串
     *
     * @return 测试字符串
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("[Permission: permissionId=").append(permissionId);
        sb.append(", permissionCode=").append(permissionCode);
        sb.append(", pcode=").append(pcode);
        sb.append(", permissionName=").append(permissionName);
        sb.append(", permissionLevel=").append(permissionLevel);
        sb.append(", url=").append(url);
        sb.append(", orderNo=").append(orderNo);
        sb.append(", remark=").append(remark);
        sb.append(", createTime=").append(createTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", version=").append(version);
        sb.append("]");

        return sb.toString();
    }
}
